$("#search").click(function(){
    if(ajaxFun("/ajax/checkAuthority/?functionId=web_user_qry&deptId=")){
        var userName = $("#userName").val();
        window.location = "/user/?userName="+userName;
    }else{
        show_err_msg("您目前没有查询用户的权限,请联系管理员"); 
    }
});
function createUser(){
   if(ajaxFun("/ajax/checkAuthority/?functionId=web_user_add&deptId="))
        window.location = "/user/edit/";
    else
        show_err_msg("您目前没有添加用户的权限,请联系管理员");
}
function userDetail(adminId){
    var query = $("#userName").val();
    var page  = $(".curr").html();
    if(ajaxFun("/ajax/checkAuthority/?functionId=web_user_modify&deptId="))
        window.location = "/user/edit/?keywords="+query+"&adminId="+adminId+"&page="+page;
    else
        show_err_msg("您目前没有修改用户的权限,请联系管理员");
}
function userStatus(adminId,status,name){
    if(ajaxFun("/ajax/checkAuthority/?functionId=web_user_setStatus&deptId=")){
        if(confirm("是否"+(status==0?"禁用'":"启用'")+name+"'用户")){
            var query = $("#search").val();
            var page  = $(".curr").html();
            var xmlhttp;
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var obj;
                    try{
                        obj =  eval('(' + xmlhttp.responseText + ')');
                    }catch(exception){
                        obj="error";
                    }
                    if(obj == "error"){
                        show_err_msg("服务链接出错！");    
                    }else{
                        if(obj.status == "succeed")
                            show_msg(obj.info,"/user/?keywords="+query+"&page="+page);
                        else if(obj.status == "fail")
                            show_err_msg(obj.info);
                        }
                    }
                }
            xmlhttp.open("POST", "/ajax/userStatus/", true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send("adminId="+adminId+"&status="+status);
        }else{
            return false;
        }
    }else{
        show_err_msg("您目前没有设置用户状态的权限,请联系管理员");
        return false;
    }
	
}
function userDelete(adminId,name){
    if(ajaxFun("/ajax/checkAuthority/?functionId=web_user_delete&deptId=")){
        if(confirm("是否删除'"+name+"'管理员！")){
            var query = $("#search").val();
            var xmlhttp;
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var obj;
                    try{
                        obj =  eval('(' + xmlhttp.responseText + ')');
                    }catch(exception){
                        obj="error";
                    }
                    if(obj == "error"){
                        show_err_msg("服务链接出错！");    
                    }else{
                        if(obj.status == "succeed")
                            show_msg(obj.info,"/user/?keywords="+query);
                        else if(obj.status == "fail")
                            show_err_msg(obj.info);
                        }
                    }
                }
            xmlhttp.open("POST", "/ajaxDelete/userDelete/", true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send("adminId="+adminId);
        }else{
            return false;
        }
    }else{
        show_err_msg("您目前没有删除用户的权限,请联系管理员");
        return false;
    }
}
function distributRole(adminId){
   if(ajaxFun("/ajax/checkAuthority/?functionId=web_user_setPermit&deptId="))
        window.location = "/user/distributroleinit/?adminId="+adminId;
    else
        show_err_msg("您目前没有给用户分配角色的权限,请联系管理员");
}
function distributAuth(adminId){
    if(ajaxFun("/ajax/checkAuthority/?functionId=web_user_setPermit&deptId="))
        window.location = "/user/distributAuthInit/?adminId="+adminId;
    else
        show_err_msg("您目前没有给用户分配权限的权限,请联系管理员");
}